package utils.extensions;

import play.templates.JavaExtensions;

/**
 * Created by eric on 2017/4/20.
 */
public class Extensions extends JavaExtensions {
    public static String cut(String str, int len) {
        return (len > str.length() - 1) ? str : str.substring(0, len) + "...";
    }

    public static String explode(String str, String elementTag, String cssClass) {
        StringBuilder sb = new StringBuilder();
        String[] tags = str.split(",");
        for(String tag: tags) {
            sb.append(String.format("<%s class=\"%s\">%s</%1$s>", elementTag, cssClass, tag));
        }
        return sb.toString();
    }
}
